package com.site.wisdom_construction.controller.trainingCheckModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.trainingCheckModule.ExamQuestionsPublicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/1/17
 * @Description
 */
@Api(tags = "公共考试试题接口")
@RestController
@RequestMapping("ExamQuestionsPublic")
@CrossOrigin
public class ExamQuestionsPublicController {
    @Autowired
    private ExamQuestionsPublicService examQuestionsPublicService;

    @ApiOperation(value = "增加公共考试试题", notes = "测试数据:")
    @PostMapping("/insertExamQuestionsPublic")
    public JsonResult insertExamQuestionsPublic(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = examQuestionsPublicService.insertExamQuestionsPublic(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入公共考试试题!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入公共考试试题失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除公共考试试题信息", notes = "测试数据:")
    @PostMapping("/deleteExamQuestionsPublic")
    public JsonResult deleteExamQuestionsPublic(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = examQuestionsPublicService.deleteExamQuestionsPublic(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除公共考试试题!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除公共考试试题失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改公共考试试题", notes = "测试数据:")
    @PostMapping("/updateExamQuestionsPublic")
    public JsonResult updateExamQuestionsPublic(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = examQuestionsPublicService.updateExamQuestionsPublic(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改公共考试试题!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改公共考试试题失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询公共考试试题", notes = "测试数据:")
    @PostMapping("/findExamQuestionsPublicByPage")
    public Page findExamQuestionsPublicByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(examQuestionsPublicService.Total(map));
        page.setItems(examQuestionsPublicService.findExamQuestionsPublicByPage(map));
        return page;
    }

    @ApiOperation(value = "根据id查询公共考试试题", notes = "测试数据:")
    @PostMapping("/findExamQuestionsPublicById")
    public OneDataResult findExamQuestionsPublicById(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(examQuestionsPublicService.findExamQuestionsPublicById(map));
        return oneDataResult;
    }
}
